<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加部门</title>
<%@ include file="/WEB-INF/jsp/kt/common/inc.jsp" %>
<script type="text/javascript" src="${_resources}js/setUserIdAndName.js"></script>
<link href='${_resources}css/style.css' type='text/css' rel='stylesheet' />
<script type="text/javascript">
var departIdNameMap;
$(function (){
	$("#department").validationEngine({
		autoHidePrompt:true,//自动隐藏
		showOnMouseOver:true,//当鼠标移出时触发
		promptPosition:'bottomLeft',//提示信息的位置
		inlineValidation: true,//是否即时验证，false为提交表单时验证,默认true  
		failure : function() {
		    layer.message("验证失败，请检查");
			return false;  
		},//验证失败时调用的函数
		ajaxFormValidation: true,//开始AJAX验证
		success : function() {
		//	$("#addForm").submit();
		}//验证通过时调用的函数 
		//onAjaxFormComplete: ajaxValidationCallback
	});
	
	
	var path='${_baseUrl}/departmentController/getParentId';
	$.ajax({
		cache:false,
		async:false,
		type:"POST",
		url:path,
		dataType:"json",
		success: function(data){
			var obj=JSON.stringify(data);
			var innerHtml="<select id='parentId' name='parentId' class='qr_select layout_table_select' onchange='getChoiceDepart();'>";
			if(obj=="[]"){
				innerHtml+="<option value=''>请选择上级部门</option>"; 
			}else{
				innerHtml+="<option value=''>请选择上级部门</option>";    
				for(var i=0;i<data.length;i++){	
						innerHtml+="<option value='"+data[i].id+"'>"+data[i].deptName+"</option>";    
				}  
			}
			innerHtml+="</select>";     
			$("#depart").html(innerHtml);
		}
	})
	
	$("#submit").click(function (){
		if($("#department").validationEngine('validate')){
			var deptName=$("#deptName").val();
			$.ajax({
				cache:false,
				async:false,
				type:"GET",
				url:"${_baseUrl}/departmentController/checkDepartMentName?name="+$("#deptName").val()+"&random="+Math.random(),
				dataType:"json",
				success: function(data){
					if(data.code == "1"){
						layer.msg(data.message);
					}else{
						var options = {
							dataType:"json",
							success:function(json){
								if(json.code == '1'){
									$("#submit").unbind("click");
									layer.msg(json.message,{shift:5},function(){
										// parent.refreshTable();
										parent.window.location.reload();//
										parent.closeWin();
									});
								}
								if(json.code == '0'){
									layer.msg(json.message);
								}
							},
							error:function(json){
								layer.msg("系统错误,请联系管理员");
							}
						};
						$('#department').ajaxSubmit(options);
					}
				},
				error:function(json){
					layer.msg("系统异常,请联系管理员");
				}
			});
		}
	});
	
	$("#cancel").click(function (){
		parent.refreshTable();
		parent.closeWin();
	});

})
 function selectUser(inputId){
	var choicedParentDepart = $("#parentId").val();
	
	var managerId = "";
	if(inputId=="chargeInDeptAdd"){
		managerId = $("#charge_id").val();//"${department.charge }";
	}else if(inputId == "interfacePerson"){
		managerId = $("#interfacePerson_id").val();//"${department.interfacePerson }";
	}else if(inputId == "superLeader"){
		managerId = $("#superLeader_id").val();//"${department.superLeader }";
	}else if(inputId == "manager"){
		managerId = $("#manager_id").val();//"${department.manager }";
	}
	
	layer.open({
        type: 2 //Page层类型
        ,area: ['641px', '350px']
        ,title: '选择人员'
        ,shade: 0.3 //遮罩透明度
        ,maxmin: true //允许全屏最小化
        ,anim: -1 //0-6的动画形式，-1不开启
        ,content: "${_baseUrl}/departmentController/showSelectDepartUserTop?inputId="+inputId+"&managerId="+managerId+"&choicedParentDepart="+choicedParentDepart+"&random="+Math.random()
    });
	
	   		
} 
/* 关闭弹出框 */
function closeWin(){
	layer.closeAll();
}
function valUserIdName(userId,userName,inputId){
	/* alert(userId,userName); */
	$("#"+inputId).val(userName);
}

function getChargeId(inputId){
	selectUser(inputId);
}

function getInterfacePersonId(inputId){
	selectUser(inputId);
}
function getSuperLeaderId(){
	var inputId="superLeader";
	selectUser(inputId);
}
function getManagerId(){
	var inputId="manager";
	selectUser(inputId);
}
</script>
<style type="text/css">
    select {
            width:100%;
            font-size: 13px;
            height:30px;
            float:left;
            line-height: 10px;
            padding-bottom:5px\9;
            border: solid 1px #d6d6d6;
            appearance:none;
            -moz-appearance:none;
            -webkit-appearance:none;
            background: url("${_resources}img/input_xiala.png") no-repeat  right center ;
            border-radius: 4px;
        }
        /*清除ie的默认选择框样式清除，隐藏下拉箭头*/
        select::-ms-expand { display: none !important; }
        
</style>
</head>
<body>
	<form name="department" id="department" action="${_baseUrl}/departmentController/add" method="post">
	<div style="overflow: auto; width:98%;margin: auto;">  
	    <table class="table table-bordered table_inline">	
	      <tr>
	        <td height="50" width="15%" align="center"><span style="color: #f00">*</span>部门名称</td>
	        <td width="35%" valign="middle">
	        	<div class="">
	        		<input type="text" name="deptName" id="deptName" class="validate[required,maxSize[25]] text_placeholder"  placeholder="请输入">
	        	</div>
	        </td>
	        <td width="15%" valign="middle" align="center"><span style="color: #f00">*</span>部门编号</td>
	        <td width="35%">
	        	<div class="">
	        		<input type="text" name="deptNumber" id="deptNumber" class="validate[required,maxSize[25],custom[onlyLetterNumber]] text_placeholder"  placeholder="请输入">
	        	</div>
	        </td>
	      </tr>
	      <tr>
	        <td width="15%" valign="middle" align="center">部门简称</td>
	        <td width="35%">
	        	<div class="">
	        		<input type="text" name="departAbbrevia" id="departAbbrevia" class="text_placeholder validate[maxSize[25]]" placeholder="请输入">
	        	</div>
	        </td>
	        <td height="50"  width="15%" align="center">上级部门</td>
	        <td width="35%" valign="middle">
	        	<div class="qr_input">
	        		<span id="depart" ></span>
	        	</div>
	        </td>
	      </tr>
	      <tr>
	         <td height="50"  width="15%" align="center"><span style="color: #f00">*</span>部门负责人</td>
	       	 <td width="35%" valign="middle">
	        	<div class="">
	        		<input style="margin-left:-5px" type="text" name="chargeName" id="charge_name" readonly class="nav_textarea validate[required,validate[maxSize[50]]"/>
	        		<input type="hidden" name="charge" id="charge_id"/>
	        		 <c:if test="${customCode eq 'siyuan17suo'}">
	        		 	<a href="javascript:;" class=""  onClick="selectUser('chargeInDeptAdd');" style="margin-left:-35px;z-index:999">
	        		 </c:if>
	        		 <c:if test="${customCode ne 'siyuan17suo'}">
	        		 	<a href="javascript:;" class=""  onClick="selectUser('charge');" style="margin-left:-35px;z-index:999">
	        		 </c:if>
	        			选择
	        		</a>
	        	</div>
	         </td>
	        
	         <td width="15%" valign="middle" align="center">部门接口人</td>
	         <td width="35%">
	        	<div class="">
	        	  <input style="margin-left:-5px" type="text" name="interfacePersonName" id="interfacePerson_name" readonly class="nav_textarea validate[maxSize[50]]">
	        	  <input type="hidden" name="interfacePerson" id="interfacePerson_id" />
	        		<a href="javascript:;" class="" onClick="selectUser('interfacePerson');" style="margin-left:-35px;z-index:999">
	        			选择
	        		</a>
	        		<br/>
	        	</div>
	         </td>
	      </tr>
	      <tr>
	        <td height="50" width="15%" align="center">上级主管领导</td>	
	        <td width="35%" valign="middle">
	        	<div class="">
	        		<input style="margin-left:-5px" type="text" name="superLeaderName" id="superLeader_name" readonly class="nav_textarea validate[maxSize[50]]">
	        		<input type="hidden" name="superLeader" id="superLeader_id" />
	       			<a href="javascript:;" class="" onClick="selectUser('superLeader');" style="margin-left:-35px;z-index:999">
	       				选择
	       			</a>
	       			<br/>
	       		</div>
	       	</td>
	        <td  width="15%" valign="middle" align="center">部门管理人</td>
	        <td width="35%">
	        	<div class="">
	        		<input style="margin-left:-5px" type="text" name="managerName" id="manager_name" readonly class="nav_textarea validate[maxSize[50]]">
	        		<input type="hidden" name="manager" id="manager_id" />
	        		<a href="javascript:;" class="" onClick="selectUser('manager');" style="margin-left:-35px;z-index:999">
	        			选择
	        		</a>
	        		<br/>
	        	</div>
	        </td>
	      </tr>
	      <tr>
	        <td height="50" width="15%" align="center">部门描述</td>
	        <td colspan="3" width="35%" valign="middle">
	        	<div class="">
	        		<textarea name="comments" id="comments" class="validate[maxSize[4000]] textarea_placeholder" placeholder="请输入"></textarea>
	        	</div>
	        </td>
	      </tr>
	    </table>
	    </div>
		<div class="submit_group">
		<shiro:hasPermission name="departmentController:add">
	        <a href="javascript:void(0);" id="submit" class="submit">保存</a>
	    </shiro:hasPermission>
		<shiro:hasPermission name="departmentController:close">
	    	<a href="javascript:;"  id="cancel" class="cancel">关闭</a>
	    </shiro:hasPermission>
	    </div>
</form>
<div id="selectDiv" style="display: none;overflow: hidden;">
	<iframe id="selectIframe" border="0" frameborder="0"></iframe>
</div>
	
</body>
</html>